package com.example.testverhorscrolling;

import android.os.Bundle;
import android.app.Activity;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.view.Menu;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class MainActivity extends Activity {

	@Override
	// protected void onCreate(Bundle savedInstanceState) {
	// super.onCreate(savedInstanceState);
	// setContentView(R.layout.activity_main);
	// }
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		TableLayout aTable = (TableLayout) findViewById(R.id.amortization);
			String[][] amortValues = this.getTestMatrix(20, 40);
			appendRows(aTable, amortValues);
	}

	private void appendRows(TableLayout table, String[][] amortization) {
		int rowSize = amortization.length;
		int colSize = (amortization.length > 0) ? amortization[0].length : 0;
		for (int i = 0; i < rowSize; i++) {
			TableRow row = new TableRow(this);

			for (int j = 0; j < colSize; j++) {
				TextView c = new TextView(this);
				System.out.println(amortization[i][j]);
				c.setText(amortization[i][j]);
				c.setPadding(3, 3, 3, 3);
				row.addView(c);
			}

			table.addView(row, new TableLayout.LayoutParams());
		}
	}

	public String[][] getTestMatrix(int filas, int columnas) {
		String[] nameCols = new String[columnas + 1];// +1 por el campo _id
		nameCols[0] = "_id";
		String[][] data = new String[columnas + 1][filas];
		for (int co = 0; co <= columnas; co++) {
			if (co == 0) {
				nameCols[0] = "_id";
			} else {
				nameCols[co] = "col" + co;
			}
			for (int fi = 0; fi < filas; fi++) {
				if (co == 0) {
					data[co][fi] = "" + co + fi;
				} else {
					data[co][fi] = "val col=" + co + " fi=" + fi;
				}
			}
		}
//		MatrixCursor cursor = new MatrixCursor(nameCols);
//		for (int fi = 0; fi < filas; fi++) {
//			String[] temp = new String[columnas + 1];
//			for (int co = 0; co <= columnas; co++) {
//				temp[co] = data[co][fi];
//			}
//			cursor.addRow(temp);
//		}
		return data;

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}
